package com.milling.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.milling.business.service.IWmsConfigInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.milling.common.annotation.Log;
import com.milling.common.core.controller.BaseController;
import com.milling.common.core.domain.AjaxResult;
import com.milling.common.enums.BusinessType;
import com.milling.business.domain.WmsBoxInfo;
import com.milling.business.service.IWmsBoxInfoService;
import com.milling.common.utils.poi.ExcelUtil;
import com.milling.common.core.page.TableDataInfo;

/**
 * 盒子信息Controller
 *
 * @author X
 * @date 2025-02-15
 */
@RestController
@RequestMapping("/business/boxinfo")
public class WmsBoxInfoController extends BaseController
{
    @Autowired
    private IWmsBoxInfoService wmsBoxInfoService;

    @Autowired
    private IWmsConfigInfoService wmsConfigInfoService;

    /**
     * 查询盒子信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:boxinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsBoxInfo wmsBoxInfo)
    {
        logger.info("清理对象类缓存 开始");
//        wmsConfigInfoService.initConfigParam();
        logger.info("清理对象类缓存 结束");
        startPage();
        List<WmsBoxInfo> list = wmsBoxInfoService.selectWmsBoxInfoList(wmsBoxInfo);
        return getDataTable(list);
    }

    /**
     * 导出盒子信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:boxinfo:export')")
    @Log(title = "盒子信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsBoxInfo wmsBoxInfo)
    {
        List<WmsBoxInfo> list = wmsBoxInfoService.selectWmsBoxInfoList(wmsBoxInfo);
        ExcelUtil<WmsBoxInfo> util = new ExcelUtil<WmsBoxInfo>(WmsBoxInfo.class);
        util.exportExcel(response, list, "盒子信息数据");
    }

    /**
     * 获取盒子信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:boxinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wmsBoxInfoService.selectWmsBoxInfoById(id));
    }

    /**
     * 新增盒子信息
     */
    @PreAuthorize("@ss.hasPermi('business:boxinfo:add')")
    @Log(title = "盒子信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsBoxInfo wmsBoxInfo)
    {
        return toAjax(wmsBoxInfoService.insertWmsBoxInfo(wmsBoxInfo));
    }

    /**
     * 修改盒子信息
     */
    @PreAuthorize("@ss.hasPermi('business:boxinfo:edit')")
    @Log(title = "盒子信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsBoxInfo wmsBoxInfo)
    {
        return toAjax(wmsBoxInfoService.updateWmsBoxInfo(wmsBoxInfo));
    }

    /**
     * 删除盒子信息
     */
    @PreAuthorize("@ss.hasPermi('business:boxinfo:remove')")
    @Log(title = "盒子信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsBoxInfoService.deleteWmsBoxInfoByIds(ids));
    }
}
